﻿using System.Threading.Tasks;

namespace Restful.Net.TestHost
{
    public class DummyUserAuthenticator : IUserAuthenticator
    {
        public async Task<IUser> AuthenticateAsync(string userName, string password)
        {
            if (userName == null || password == null)
            {
                return await Task.Factory.StartNew<IUser>(() => null);
            }
            if (userName == "bjorn" && password == "12345")
            {
                return await Task.Factory.StartNew<IUser>(() => new DummyUser(userName, 1, true));
            }

            return null;
        }

        private class DummyUser : IUser<long>
        {
            public DummyUser(string userName, long identifier, bool isAuthenticated)
            {
                UserName = userName;
                Identifier = identifier;
                IsAuthenticated = isAuthenticated;
            }

            public bool IsAuthenticated
            {
                get;
                private set;
            }
            public string UserName
            {
                get;
                private set;
            }
            public long Identifier
            {
                get;
                set;
            }
        }
    }
}